<template>
  <div>
    <h1>one-page</h1>
    <div>测试元素</div>
    <input type="text" v-focus="666">
    <button @click="showBox = false">关闭组件</button>
    <div class="container-sel" v-clickOutside="handleClose" v-if="showBox">
      <div class="sel-btn" @click="switchDrop">点击显示菜单</div>
      <div class="sel-menu" v-show="showdrop">
        这里是菜单区域
      </div>
    </div>
    <h2 v-time="1561241343948"></h2>
  </div>
</template>

<script>
export default {
  name: 'onepage',
  data() {
    return {
      title: 'onepage',
      showdrop: false,
      showBox: true
    }
  },
  methods: {
    switchDrop() {
      this.showdrop = !this.showdrop
    },
    handleClose() {
      console.log('触发外部点击事件')
      this.showdrop = false
    }
  },
}
</script>

<style lang="less" scoped>
.container-sel {
  position: relative;
  width: 100%;
  min-width: 80px;
  max-width: 150px;
  height: 30px;
  .sel-btn {
    width: 100%;
    min-width: 150px;
    max-width: 250px;
    height: 30px;
    line-height: 30px;
    font-size: 14px;
    text-align: center;
    color: #fff;
    background-color: skyblue;
    border-radius: 5px;
    cursor: pointer;
  }
  .sel-menu {
    position: absolute;
    top: 40px;
    left: 0;
    width: 100%;
    min-height: 100px;
    box-sizing: border-box;
    padding: 5px;
    border-radius: 5px;
    background-color: #f4f4f4;
    box-shadow: 2px 2px 3px grey;
  }

}
</style>